﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="../front.jsp"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <link rel="stylesheet" type="text/css" href="${front}/detail/style/css/index.css"/>
    <script src="${front}/detail/style/js/jquery.js"></script>
    <script type="text/javascript">
        /** // 删除菜品项
         function removeSorder(node) {
			var gid = node.lang;
			window.location.href = "/wirelessplatform/sorder.html?method=removeSorder&gid="+gid;
		}

         // 修改菜品项数量
         function alterSorder(node) {
			var snumber = node.value;
			var gid = node.lang;
			window.location.href = "/wirelessplatform/sorder.html?method=alterSorder&gid="+gid+"&snumber="+snumber;
		}
         */
        // 下单
        function genernateOrder() {
            window.location.href = "clientOrderList.html";
        }
    </script>
</head>

<body style="text-align: center">
<a href="${front}/detail/clientOrderList.jsp">订单</a>
<c:if test="${sessionScope.user == null}">
    <a href="${base}/user/login.jsp">登陆</a>
</c:if>
<c:if test="${sessionScope.user != null}">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    欢迎：
    ${sessionScope.user.userName}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="user?method=userLogout">退出登陆</a>
</c:if>
<c:if test="${sessionScope.user != null}">
    <a href="${base}/order?method=findOrder">历史订单</a>
</c:if>


<div id="all">
    <div id="menu">
        <!-- 餐车div -->
        <div id="count">
            <table align="center" width="100%">
                <tr height="40">
                    <td align="center" width="20%">菜名</td>
                    <td align="center" width="20%">单价</td>
                    <td align="center" width="20%">数量</td>
                    <td align="center" width="20%">小计</td>
                    <td align="center" width="20%">操作</td>
                </tr>
                <c:forEach items="${sessionScope.dinnerCarList}" var="dinnerCar">
                    <tr height="60">
                        <td align="center" width="20%">${dinnerCar.detailFoodName}</td>
                        <td align="center" width="20%">￥${dinnerCar.detailPrice/100.0}</td>
                        <td align="center" width="20%">
                            <input id="detailNumber${dinnerCar.detailFoodId}" type="number"
                                   value="${dinnerCar.detailNumber}" size="3" lang="3"
                                   onchange="updateDinnerCarList(this,${dinnerCar.detailFoodId},this.value)"/>
                        </td>
                        <td align="center" id="updateDinnerCarList${dinnerCar.detailFoodId}"
                            width="20%">${dinnerCar.detailTotalPrice/100.0}</td>
                        <td align="center" width="20%">
                            <input type="button" value="删除" class="btn_next" lang="3"
                                   onclick="deleteDinnerCarList(this,${dinnerCar.detailFoodId})"/>
                        </td>
                    </tr>
                </c:forEach>
                <tr>
                    <td colspan="6" align="right">总计:
                        <span style="font-size:36px;">&yen;
								<span id="totalPrice" style="font-size:36px;">${sessionScope.totalPrice/100.0}</span>
							</span>
                        <label
                                id="counter" style="font-size:36px"></label>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" style="margin-left: 100px; text-align: center;" align="right">
                        <input type="hidden" name="bId" value="">

                        <input type="button" value="下单" class="btn_next" onclick="generatorOrder()"/>


                    </td>
                </tr>
            </table>
        </div>
    </div>

    <!-- 右边菜系列表，菜品搜索框  -->
    <div id="dish_class">
        <div id="dish_top">
            <ul>
                <li class="dish_num"></li>
                <li>
                    <a href="clientCart.jsp">
                        <img src="${front}/detail/style/images/call2.gif"/>
                    </a>
                </li>
            </ul>
        </div>

        <div id="dish_2">
            <ul>
                <c:forEach items="${sessionScope.foodTypeList}" var="type">
                    <li>
                        <a href="${base}/front?method=findFoodToPage&foodTypeId=${type.typeId}&foodName=${foodName}">${type.typeName}</a>
                    </li>
                </c:forEach>

            </ul>
        </div>
        <div id="dish_3">
            <!-- 搜索菜品表单  -->
            <form action="${base}/front?method=findFoodToPage" method="post">
                <table width="166px">
                    <tr>
                        <td>
                            <span style="font-size: 20px">菜品名称:</span><input type="text" value="${foodName}"
                                                                             id="dish_name" name="foodName"
                                                                             class="select_value"/>
                            <%--<input type="hidden" value="selectFood" name="method">--%>
                        </td>
                    </tr>
                    <tr>
                        <td><input type="submit" id="sub" value=""/></td>
                    </tr>
                    <tr>
                        <td>
                            <a href="${base}/front?method=findFoodToPage">
                                <img src="${front}/detail/style/images/look.gif"/>
                            </a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
</body>

<script>
    //删除餐车项
    function deleteDinnerCarList(obj, foodId) {
        console.log(obj);
        var url = "${base}/dinnercar?method=deleteFoodToDinnerCar&foodId=" + foodId;
        $.get(url, null, function (result) {
            if (result.success) {
                //修改总价
                $("#totalPrice").text(result.tprice / 100.0);
                //删除当前行
                $(obj).parent().parent().remove();
            } else {
                alert("删除失败");
            }
        }, "json");
    }

    //修改餐车项
    function updateDinnerCarList(obj, foodId, number) {
        //console.log(obj);
        console.log(number);
        var url = "${base}/dinnercar?method=updateDinnerCar&foodId=" + foodId + "&number=" + number;
        $.get(url, null, function (result) {
            if (result.success) {
                //修改总价
                $("#totalPrice").text(result.totalPrice / 100.0);
                //修改当前行的值
                //var detailTotalPrice = parseInt(result.detailTotalPrice);
                console.log(result.detailTotalPrice);
                //console.log(detailTotalPrice);
                $("#updateDinnerCarList" + foodId).text(result.detailTotalPrice / 100.0);
            } else {
                alert("数量非法");
                location.href = "";
            }
        }, "json");
    }

    //创建订单
    function generatorOrder() {

        location.href = "${base}/order?method=addOrder";
    }
</script>


</html>
